package top.xtcoder.jdcbase.base.core;

import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;

import com.github.xiaoymin.knife4j.core.util.StrUtil;

public class UniqueNameGenerator extends AnnotationBeanNameGenerator{
	@Override
	public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
		
		if(definition instanceof AnnotatedBeanDefinition) {
			String beanName = determineBeanNameFromAnnotation((AnnotatedBeanDefinition)definition);
			if(StrUtil.isNotBlank(beanName)) {
				return beanName;
			}else {
				beanName = definition.getBeanClassName();
				return beanName;
			}
		}
		return buildDefaultBeanName(definition, registry);
	}
}
